<?php

// 加载头部
function load_head($title = '')
{
    ?>

    <!DOCTYPE html>
    <html>

    <head>
        <link rel="shortcut icon" href="img/logo.jpeg" type="image/x-icon" />
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title><?php echo $title; ?></title>
        <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="css/main.css">
        <link rel="stylesheet" href="css/news.css">

    </head>

    <body>
        <div class="bdimg"></div>

        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
                        <span class="sr-only">切换导航</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>

                    <img src="img/logo.jpeg" alt="江苏大学" class="navbar-brand">
                    <a class="navbar-brand" href="index.php">
                        江苏大学信息站
                    </a>

                </div>
                <div class="collapse navbar-collapse" id="navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li class="mode-news <?php echo_active('news'); ?>"><a href="?mode=news">新闻</a></li>
                        <li class="mode-notification <?php echo_active('notification'); ?>"><a href="?mode=notification">消息栏目</a></li>
                        <li class="mode-notification <?php echo_active('xyzt'); ?>"><a href="?mode=xyzt">校园杂谈</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">

                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <?php
                                global $current_user_info;
                                if (!$current_user_info) {
                                    echo '用户';
                                } else {
                                    echo $current_user_info['name'];
                                }
                                ?>
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <?php
                                if (!$current_user_info) { // 未登录
                                    ?>
                                    <li class="<?php echo_active('login'); ?>"><a href="?mode=login">登录</a></li>

                                    <div class="divider"></div>
                                    <li class="<?php echo_active('reg'); ?>"><a href="?mode=reg">注册</a></li>
                                <?php
                            } else {
                                ?>
                                    <li><a href="?mod=admin:logout">退出</a></li>
                                <?php
                            }
                            ?>

                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    <?php
}

// 控制active
function echo_active($mod)
{
    if ($_GET['mode'] == $mod) {
        echo ('active');
    }
}

// 加载底部
function load_foot()
{
    ?>
        <div class="panel panel-body" style="text-align: center;">
            当前时间: <span id="current_time"></span>
        </div>

        <!-- canvas -->
        <canvas id="canvas-spirit"></canvas>

        <script src="js/canvas-spirit.js"></script>
        <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
        <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

        <script>
            function get_current_time() {
                var date = new Date();
                var year = date.getFullYear(); //获取当前年份   
                var mon = date.getMonth() + 1; //获取当前月份   
                var da = date.getDate(); //获取当前日   
                var day = date.getDay(); //获取当前星期几   
                var h = date.getHours(); //获取小时   
                var m = date.getMinutes(); //获取分钟   
                var s = date.getSeconds(); //获取秒
                var d = $('#current_time').html(year + '年' + mon + '月' + da + '日' + '星期' + day + ' ' + h + ':' + m + ':' + s);
            }
            get_current_time();
            setInterval(get_current_time, 1000);
        </script>
    </body>

    </html>
<?php
}

/**
 * 加载系统或插件的模板（或文件）
 */
function template($file)
{
    return include 'templates/' . $file . '.php';
}
?>